cmake_minimum_required(VERSION 3.10)
project(sinx_ispc)

set(CMAKE_CXX_STANDARD 17)

set(CMAKE_ISPC_LINK_EXECUTABLE "/snap/bin/ispc")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mavx")

file(MAKE_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/objs)

message("CMAKE_CURRENT_SOURCE_DIR is " ${CMAKE_CURRENT_SOURCE_DIR})

add_custom_command(
    OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/objs/sinx_ispc.o ${CMAKE_CURRENT_SOURCE_DIR}/objs/sinx_ispc.h
    COMMAND ${CMAKE_ISPC_LINK_EXECUTABLE} -O2 --target=avx512skx-x64 ${CMAKE_CURRENT_SOURCE_DIR}/aaaa.ispc -o ${CMAKE_CURRENT_SOURCE_DIR}/objs/sinx_ispc.o -h ${CMAKE_CURRENT_SOURCE_DIR}/objs/sinx_ispc.h
    DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/aaaa.ispc
    COMMENT "Using ispc to compile the ispc file to header file and object file"
)

set(SOURCE_FILE main_sinx.cpp)
set(ISPC_OBJECT_FILE objs/sinx_ispc.o)
set(ISPC_HEADER_FILE objs/sinx_ispc.h)

add_executable(sinx_ispc ${SOURCE_FILE} ${ISPC_OBJECT_FILE})
#   target_compile_options(sinx_ispc PUBLIC -mavx)

target_link_libraries(sinx_ispc m)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/objs)